<?php
   namespace Home\Controller;
  use think\Controller;
 class UserController extends Controller {
    public function index(){
      $m=D('User');
      $arr=$m->select();
      $this->assign('data',$arr);
      $this->display();
    }

    public function del(){
       $m=D('User');
       $id=$_GET['id'];
       $count=$m->delete($id);
       if ($count>0)
       	 {
       	 	$this->success('数据删除成功') ;
       	 }
       	else
       		$this->error('数据删除失败') ;
    }
     
     public function modify(){
      
      $id=$_GET['id'];
      $m=D('User');
      $arr=$m->find($id);
      $this->assign('data',$arr);

      $this->display();
     }
     
     public function add(){

      $this->display();
     }
     public function create(){
      $m=D('User');
      $m->username=$_POST['username'];
      $m->id=$_POST['id'];
      $m->sex=$_POST['sex'];
      $count=$m->add();
      if ($count>0)
         {
          $this->success('数据创建成功','index',1) ;
         }
        else{
          $this->error('数据创建失败','index',1) ;
      $this->display();
     }
   }

     public function update(){
      
       $m=D('User');
       $data['id']=$_POST['id'];
      $data['username']=$_POST['username'];
      $data['sex']=$_POST['sex'];
      $count=$m->save($data);
      if ($count>0)
         {
          $this->success('数据修改成功','index',1) ;
         }
        else{
          $this->error('数据修改失败','index',1) ;
        }

     }

     public function search(){
      $m=D('User');
      if( $_POST['username']!=NULL){
     $serach['username']=array('like',$_POST['username']);
       }
      if( $_POST['sex']!=NULL){
       $serach['sex']=array('EQ',$_POST['sex']);
     }
      $count=$m->where($serach)->select();
      
      $this->assign('data',$count);
      $this->display('index');
      }
}

 ?>